﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure.ServiceRuntime;
using System.Diagnostics;
using com.dynamicdeploy.client;
using System.Threading;
using Microsoft.Web.Administration;
using System.IO;
using com.dynamicdeploy.provisioningutils;

namespace SimpleWeb
{
    public class WebRole : RoleEntryPoint
    {
        #region Properties and variables
        private Process proc;
        private const double DefaultSampleRateInSecs = 3600.0;
        private static string MachineName = Environment.MachineName;
        private static string logLevel = "error";
        private static string bootstrapperCommandsContainer = "";
        public const string GENERAL_MSG_SUBJECT = "Important Message from Dynamic>>Deploy.";
        #endregion
        const string LOCAL_WEB_CONFIG_NAME = "ReplaceWebConfig.{0}";
        const int MAX_RETRIES = 10;
        #region Windows Azure override methods
       
        

        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("WebRole Run entry point called", "Information");

            //PluginCalls.SetConfigurationPublisher();
            //CloudBlobClient blobClient = CloudStorageAccount.FromConfigurationSetting("StorageAccountConnectionString").CreateCloudBlobClient();
            //string uploadDir = @"C:\download\umbraco501containers";

            //string[] directories = Directory.GetDirectories(uploadDir);
            //string extractContainerName = null;
            //foreach (string d in directories)
            //{
              
            //        extractContainerName = Path.GetFileName(d);
               
            //    CloudBlobContainer c = blobClient.GetContainerReference(extractContainerName);
            //    c.CreateIfNotExist();
            //    Utils.UploadDirectoryRecursive(d, c);

            //}

            //PluginCalls.ReplaceWebConfigFile();
           PluginCalls.ReplaceAnyConfigFile();
            base.Run();
            while (true)
            {
                // Trace.TraceError("Running without cache. Please fix cache for performance.");
                Thread.Sleep(100000);

            }
        }
        /// <summary>
        /// Windows Azure start method
        /// </summary>
        /// <returns></returns>
        public override bool OnStart()
        {
           
            return base.OnStart();
        }


        /// <summary>
        /// Windows Azure stop method
        /// </summary>
        public override void OnStop()
        {

            base.OnStop();

        }
      

        #endregion

       


    }
}